<?php
namespace App\Controllers\Goods;
use App\Libs\Goods\Goods;

/**
*	获取热门商品
*/
class GetHotGoods extends \App\Libs\Base\BaseAction
{
    protected function beforeRun() {
        parent::beforeRun();
        //$this->needLogin = TRUE;
    }
	
	public function execute(){
		$params['size'] = (int)$this->request->get( 'size' );//展示条数
		$params['page'] = (int)$this->request->get( 'page' );//页数
		$params['lnt'] = $this->request->get( 'lnt' );//经度
		$params['lat'] = $this->request->get( 'lat' );//维度
		$params['city'] = (int)$this->request->get( 'city' );//城市
		if( empty( $params['lnt'] ) ){
			return \App\Libs\Views\Json::view( 1 , '请选择相应地理位置！', NULL);
		}
		if( empty( $params['city'] ) ){
			return \App\Libs\Views\Json::view( 1 , '城市参数错误', NULL);
		}
		if( $params['page'] <= 0 ){
			$params['page'] = 1;
		}
		if( $params['size'] <= 0 ){
			$params['size'] = 10;
		}

		$data = Goods::hotGoods( $params );
		if( !empty( $data ) ){
			foreach($data as $k=>$v){
				$data[$k]['distance'] = \App\Libs\Helper\CommonHelper::transformDis($v['distance']);
			}
		     $resultInfoArr = array_values($data);	
			return \App\Libs\Views\Json::view(0, '成功', $resultInfoArr);
		}else{
			return \App\Libs\Views\Json::view(0, '未查到信息', null);	
		}
	}
}
